import {getWelComTextByTime, strToBinary} from '@/utils'
import {HACKER_NAME} from '@/constant'

export default {
    userInfo: state => state.app.userInfo,
    isCollapse: state => {
        return state.app.isCollapse
    },
    hasLogin: (_, getters) => {
        return !!getters.token.length
    },
    token: state => {
        const {userInfo} = state.app
        if (!userInfo) return ''
        if (userInfo.hasOwnProperty('token')) return userInfo.token
        return ''
    },
    userList: state => state.users.userList,
    welComeText: (state, getters) => {
        const {currentHour} = state.app
        const {userInfo} = getters
        let name = ''
        if (userInfo.hasOwnProperty('nickname')) {
            name = userInfo.nickname
        } else {
            name = 'admin'
        }
        return getWelComTextByTime(currentHour, name)
    },
    iconList: state => state.icon.iconList,
    unReadCount: state => state.app.unReadCount,
    isDev: () => process.env.NODE_ENV === 'development',
    isWWM: state => {
        const {userInfo} = state.app
        if (!userInfo.hasOwnProperty('nickname')) return false
        const {nickname} = userInfo
        return strToBinary(nickname) === HACKER_NAME
    }
}
